var strFullPath=window.document.location.href;
var strPath=window.document.location.pathname;
var pos=strFullPath.indexOf(strPath);
var prePath=strFullPath.substring(0,pos);
var project = window.location.pathname.split("/")[1];
var url = prePath+"/"+project+"/publishController/publishNotice.wm"
$(function () {
    var teacher_id = $("#hidden").val();
    var class_id = $("#class2 option:selected").val();
    //alert(class_id);
    var chose = document.getElementsByName("radio");
    $("#toptitle").html("发布作业或通知");
    $("#publishNotice").hide();
    $("#publishJob").show();
    $(".king-btn-demo2").click(function () {
        var noticeContent = $("#noticeDetails").val();
        var test1 ="";
       if(test1==noticeContent) {
           alert("通知内容为空！");
       }else if(class_id==null){
           alert("请先建立班级！");
       }else{
           var isTop;
           var tip="notice";
           for(var i= 0;i<chose.length;i++){
               if(chose[i].checked){
                   isTop = chose[i].value;
               }
           }
        $.post(url,{class_id:class_id,
            teacher_id:teacher_id,
        noticeContent:noticeContent,
        tip:tip,isTop:isTop},function (result) {
            if(result.msg=="yes"){
                alert("发布通知成功！");
                window.location.reload();
            }else{
                alert("系统错误，发布失败！");
            }
        },"json")
       }
    });
    $(".king-btn-demo1").click(function () {
        var jobDetails = $("#jobDetails").val();
        var class_id=$("#class1 option:selected").val();
        var teacher_id = $("#hidden").val();
        var a;
        var b;
        var title = $("#title").val();
        if(title==""){
            alert("请写作业标题!");
        }else if(class_id==null){
            alert("请先建立班级！");
        }else{
            //alert("clsaa_id:"+class_id+"job:"+jobDetails+"tea:"+teacher_id+"time:"+startTime+endTime);
            
            var tip = "job";
            var startTime = $("#plugin16_demo1_3").val();
            var endTime = $("#plugin16_demo1_4").val();
            $.post(url,{tip:tip,
            teacher_id:teacher_id,
            class_id:class_id,
            jobDetails:jobDetails,
            startTime:startTime,title:title,
            endTime:endTime},function (result) {
                if(result.msg="yes"){
                    alert("发布作业成功！");
                    window.location.reload();
                }else{
                    alert("系统错误！发布作业失败！");
                }
            },"json");
        }
    });
})
function changeTip(id) {
    var select = document.getElementById(id);
    if(select.value==1){
        $("#publishNotice").slideUp("slow");
        $("#publishJob").slideDown("slow");
    }else if(select.value==2 ){
        $("#publishJob").slideUp("slow");
        $("#publishNotice").slideDown("slow");
    }else {
        $("#publishNotice").slideUp("slow");
        $("#publishJob").slideUp("slow");
    }
}